package com.yzf.wisecoder.controller;

import com.yzf.wisecoder.wisecodercommon.response.Response;
import com.yzf.wisecoder.wisecodercommon.vo.DingUserVo;
import com.yzf.wisecoder.wisecoderservice.service.DingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author jianghuiyong
 * @Description 用户控制
 * @date 2020/5/8 14:21
 */
@RequestMapping("/sys/user")
@AllArgsConstructor
@Api(value = "用户控制", tags = "用户控制")
@RestController
public class UserController {

    private final DingService dingService;

    /**
     * 登录接口(空接口，用于跳转sso)
     *
     * @return
     */
    @GetMapping("/login")
    @ApiOperation("登录")
    public Response login() {
        return Response.buildSuccessResponse();
    }

    /**
     * 获取钉钉用户列表
     *
     * @param username
     * @return
     */
    @GetMapping("/getDingUsers")
    @ApiOperation(value = "获取钉钉用户列表")
    public Response<List<DingUserVo>> getDingUsers(@RequestParam(value = "username", required = false) String username) {
        List<DingUserVo> list = dingService.getDingUsers(username);
        return Response.buildSuccessResponseWithData(list);
    }

    /**
     * 查询当前登录用户
     *
     * @return
     */
    @GetMapping("/getLoginUser")
    @ApiOperation(value = "查询当前登录用户信息")
    public Response<DingUserVo> getLoginUserInfo() {
        DingUserVo dingUserVo = dingService.getLoginUser();
        return Response.buildSuccessResponseWithData(dingUserVo);
    }


}
